<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>Ajax 应用</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
  </head>
  <script type="text/javascript">
  var xmlHttp;
  //创建XMLHttpRequest对象
  function createHttpRequest(){
  if(window.ActiveXObject){
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
  else if(window.XMLHttpRequest){
  xmlHttp=new XMLHttpRequest();}}
  function beginCheck(){
  var xh=document.all.xh.value;
  if(xh==""){
  alert("对不起，请输入注册学号！");
  return;}
  createHttpRequest();
  xmlHttp.onreadystatechange=processor;
  xmlHttp.open("get","CheckUser?xh="+xh);
  xmlHttp.send(null);}
  //处理状态改变函数
  function processor(){
  var responseContext;
  if(xmlHttp.readyState==4){
  if(xmlHttp.status==200){
  responseContext=xmlHttp.responseText;
  if(responseContext.indexOf("true")!=-1){
  alert("恭喜你，该学号有效！");}
  else{
  alert("对不起，该学号已经被注册！");}}}}</script>
  
  <body>
    <form action="">
    学号：<!-- 当输入框改变是执行beginCheck()函数 -->
    <input type="text" name="xh" onchange="beginCheck()"/>
    口令：<input type="password" name="kl"/>
       <input type="submit" value="注册"/>
       </form>
  </body>
</html>
